/*
 *   Copyright (C) 2009  Jens Kieselbach
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You may obtain a copy of the License at http://www.gnu.org/licenses/gpl.html
 */
package de.kieselbach.grootional

import de.kieselbach.swing.*

import com.jgoodies.looks.*
import com.jgoodies.looks.plastic.*
import com.jgoodies.looks.plastic.theme.*
import groovy.swing.*
import javax.swing.*
import java.util.logging.*

public class Main {

    final static def UI_RESOURCES_PATH = '/de/kieselbach/grootional/resource/uiresources.xml'
    
    static void main(args) {

        SwingUtilities.invokeAndWait {

			//PlasticLookAndFeel.setFontPolicy(FontPolicies.getTransitionalPlasticPolicy())
			Options.setPopupDropShadowEnabled(true)
			PlasticLookAndFeel.setPlasticTheme(new Silver())
			new SwingBuilder().lookAndFeel(new PlasticXPLookAndFeel())
            try {
                def res = new UIResources(getClass().getResourceAsStream(UI_RESOURCES_PATH))
                setDefaults(res)

                def frame = new MainFrame(res)
                frame.show()
            }
            catch (Exception ex) {
                Logger.getLogger(getClass().name).log(Level.SEVERE, 'Unable to load the ui resources!', ex)
                System.exit(0)
            }
        }
    }

    static def setDefaults(def uires) {

        def bundle = uires.resourceBundles['gui']

        PaneBuilder.okText = bundle.getString('common.ok')
        PaneBuilder.cancelText = bundle.getString('common.cancel')
        PaneBuilder.closeText = bundle.getString('common.close')
        PaneBuilder.yesText = bundle.getString('common.yes')
        PaneBuilder.noText = bundle.getString('common.no')
        PaneBuilder.detailsText = bundle.getString('common.details')

        PaneBuilder.okIcon = uires.images['ok16']
        PaneBuilder.closeIcon = PaneBuilder.cancelIcon = uires.images['cancel16']
        PaneBuilder.detailIcon = uires.images['find16']

        PaneBuilder.errorIcon = uires.images['dialog-error']
        PaneBuilder.infoIcon = uires.images['dialog-info']
        PaneBuilder.questionIcon = uires.images['dialog-question']
        PaneBuilder.warningIcon = uires.images['dialog-warning']

    }
}
